package com.example.demo.tests;

import com.example.demo.commen.Utils;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;

public class LoginPage extends Utils {

    public static String url = "http://127.0.0.1:8080/blog_login.html";
    public LoginPage() {
        super(url);
    }

    //检查页面是否加载成功！！！
    public void loginPageRight() throws InterruptedException {
        driver.findElement(By.cssSelector("body > div.nav > a:nth-child(4)"));
    }

    //检查登录功能
    public void LoginSuc() throws InterruptedException {
        driver.findElement(By.cssSelector("#username")).sendKeys("zhangsan");
        driver.findElement(By.cssSelector("#password")).sendKeys("123456");

        driver.findElement(By.cssSelector("#submit")).click();

        //检查登陆后，是否登陆成功， 检查是否有“查看全文” 按钮
        driver.findElement(By.cssSelector("body > div.container > div.right > div:nth-child(2) > a"));


        //页面标签来检查是否登录成功
        String ex = driver.getTitle();
        assert ex.equals("博客列表页");

        driver.navigate().back();


    }

    //检查登录功能---登陆失败
    public void LoginFail() throws InterruptedException {
     /*   driver.findElement(By.cssSelector("#username")).clear();
        driver.findElement(By.cssSelector("#password")).clear();*/

        driver.navigate().refresh();

        driver.findElement(By.cssSelector("#username")).sendKeys("zhangsan11");
        driver.findElement(By.cssSelector("#password")).sendKeys("123456");

        driver.findElement(By.cssSelector("#submit")).click();

        Thread.sleep(2000);
        Alert alert = driver.switchTo().alert();
        //确认
        alert.accept();

       // driver.quit();

    }



}
